var t = getApp();

Page({
    data: {
        condition: !0,
        answer: "咨询已受理，正在处理中，请耐心等待...",
        pic: "../../images/20.png",
        canIu: !1
    },
    onLoad: function() {
        this.sessValid(), t.GetUrl(), 1 == wx.canIUse("button.open-type.contact") && this.setData({
            canIu: !0
        });
    },
    sessValid: function() {
        wx.request({
            url: t.url + "addon/Pubdata/Pubdata/sessValid",
            data: {},
            method: "GET",
            header: {
                "Content-Type": "application/json",
                Cookie: "PHPSESSID=" + wx.getStorageSync("PHPSESSID")
            },
            success: function(a) {
                console.log(a.data), 0 == a.data && t.WxLogin();
            },
            fail: function(a) {
                t.WxLogin();
            }
        });
    },
    makeAsk: function(a) {
        wx.showToast({
            title: "工单创建中..",
            icon: "loading",
            duration: 2e4
        });
        var e = this, o = this.data.Amount, n = this.data.contact, c = wx.getStorageSync("userInfo"), s = this.data.askdata;
        wx.request({
            url: t.url + "addon/Askplat/Askplat/addAsk",
            data: {
                nickName: c.nickName,
                paysum: o,
                contact: n,
                formId: a,
                ask: s
            },
            method: "POST",
            header: {
                "content-type": "application/x-www-form-urlencoded",
                Cookie: "PHPSESSID=" + wx.getStorageSync("PHPSESSID")
            },
            success: function(t) {
                console.log("id:", t.data), e.templateSend(a, t.data), wx.hideToast();
            },
            fail: function(t) {
                wx.hideToast(), wx.showModal({
                    title: "提示",
                    content: "当前网络不稳定，创建工单失败，请尽快联系‘合同起草助手’客服",
                    showCancel: !1,
                    success: function(t) {
                        t.confirm ? console.log("用户点击确定") : t.cancel && console.log("用户点击取消");
                    }
                });
            },
            complete: function(t) {}
        });
    },
    wxpay: function(a) {
        this.setData({
            askdata: a.detail.value.text,
            Amount: a.detail.value.price,
            contact: a.detail.value.contact
        });
        var e = a.detail.value.price, o = a.detail.value.text, n = a.detail.value.contact;
        if (!e || e.length <= 0) wx.showModal({
            title: "提示",
            content: "你没有选择价格，请回到界面选择价格！",
            showCancel: !1,
            success: function(t) {
                t.confirm || t.cancel;
            }
        }); else if (!o || o.length < 1) wx.showModal({
            title: "提示",
            content: "你没有填写问题，请回到输入框输入你的问题！",
            showCancel: !1,
            success: function(t) {
                t.confirm ? console.log("用户点击确定") : t.cancel && console.log("用户点击取消");
            }
        }); else {
            wx.showToast({
                title: "正在发起支付",
                icon: "loading",
                duration: 16e3
            });
            var c = this, s = wx.getStorageSync("userInfo"), n = this.data.contact, e = a.detail.value.price;
            wx.request({
                url: t.url + "addon/Askplat/Askplat/charge",
                data: {
                    Amount: e,
                    nickName: s.nickName,
                    contact: n,
                    itemclass: "合同法律咨询"
                },
                method: "POST",
                header: {
                    "content-type": "application/x-www-form-urlencoded",
                    Cookie: "PHPSESSID=" + wx.getStorageSync("PHPSESSID")
                },
                success: function(t) {
                    wx.hideToast(), wx.requestPayment({
                        timeStamp: t.data.timeStamp,
                        nonceStr: t.data.nonceStr,
                        package: t.data.package,
                        signType: "MD5",
                        paySign: t.data.paySign,
                        success: function(a) {
                            console.log(a);
                            var e = t.data.package.substr(10);
                            c.makeAsk(e), c.MailToUs(), c.setData({
                                condition: !1,
                                inputTxt: ""
                            });
                        }
                    });
                },
                fail: function(t) {
                    wx.hideToast(), wx.showToast({
                        title: "无法连接网络",
                        icon: "loading",
                        duration: 2e3
                    });
                }
            });
        }
    },
    templateSend: function(a, e) {
        wx.request({
            url: t.url + "addon/Askplat/Askplat/templateSend",
            data: {
                itemclass: "合同法律咨询",
                id: e,
                formId: a,
                Amount: this.data.Amount
            },
            method: "POST",
            header: {
                "content-type": "application/x-www-form-urlencoded",
                Cookie: "PHPSESSID=" + wx.getStorageSync("PHPSESSID")
            },
            success: function(t) {
                console.log("自动发模板消息", t);
            }
        });
    },
    MailToMe: function(a) {
        wx.request({
            url: t.url + "addon/Pubdata/Pubdata/MailToCs",
            data: {
                itemclass: "委托审查合同",
                id: a,
                Amount: this.data.Amount
            },
            method: "POST",
            header: {
                "content-type": "application/x-www-form-urlencoded",
                Cookie: "PHPSESSID=" + wx.getStorageSync("PHPSESSID")
            },
            success: function(t) {
                console.log("发提示邮件给客服人员", t);
            }
        });
    },
    MailToUs: function() {
        var a = wx.getStorageSync("userInfo");
        wx.request({
            url: t.url + "addon/Pubdata/Pubdata/MailToUs",
            data: {
                itemclass: "合同法律咨询（问一问）",
                Amount: this.data.Amount,
                nickName: a.nickName
            },
            method: "POST",
            header: {
                "content-type": "application/x-www-form-urlencoded",
                Cookie: "PHPSESSID=" + wx.getStorageSync("PHPSESSID")
            },
            success: function(t) {
                console.log("发提示邮件给客服人员", t);
            }
        });
    },
    backtoCover: function() {
        wx.switchTab({
            url: "../MyCover/MyCover"
        });
    },
    toQuestion: function() {
        wx.redirectTo({
            url: "../MyAsk/MyAsk?Listurl=Askplat/Askplat/&TopName=我咨询过的问题"
        });
    },
    onShareAppMessage: function(t) {
        return "button" === t.from && console.log(t.target), {
            title: "合同起草助手",
            path: "",
            success: function(t) {},
            fail: function(t) {}
        };
    },
    closepage: function() {
        this.setData({
            condition: !0
        });
    },
    callus: function() {
        wx.makePhoneCall({
            phoneNumber: wx.getStorageSync("CsTelphone")
        });
    }
});